package demo3;

/**
 * 反转链表
 * https://leetcode.cn/problems/UHnkqh/
 */
class Solution {
    public ListNode reverseList(ListNode head) {
        return dfs(head);
    }

    private ListNode dfs(ListNode head) {
        // 出口
        if(head == null || head.next == null) {
            return head;
        }
        // 方法体
        ListNode newhead = dfs(head.next);
        head.next.next = head;
        head.next = null;
        return newhead;
    }
}